//处理tree数据结构
export function formatOrganizationTreeData(data, type) {
  function formatNode(node, level) {
    const idMap = (type === 'branchAdmin') ? {
      1: node.branchId,
      2: node.majorId,
      3: node.classId
    } : {
      1: node.schoolId,
      2: node.branchId,
      3: node.majorId,
      4: node.classId
    }
    const nameMap = (type === 'branchAdmin') ? {
      1: node.branchName,
      2: node.majorName,
      3: node.className
    } : {
      1: node.schoolName,
      2: node.branchName,
      3: node.majorName,
      4: node.className
    }
    const nodeId = idMap[level] + '_' + node.type
    const nodeName = nameMap[level]
    return {
      ...node,
      name: nodeName,
      id: nodeId,
      level,
      children: (node.branchList || node.majorList || node.classList || []).map(childNode => formatNode(childNode, level + 1))
    }
  }

  return data.map(node => formatNode(node, 1))
}
